<template>
  <div id="index"
       ref="appRef">
    <div class="bg">
      <dv-loading v-if="loading">Loading...</dv-loading>
      <div v-else
           class="host-body">
        <div class="d-flex jc-center">
          <dv-decoration-10 class="dv-dec-10" />
          <div class="d-flex jc-center">
            <dv-decoration-8 class="dv-dec-8"
                             :color="['#568aea', '#000000']" />
            <div class="title">
              <span class="title-text">盐南高新区村（社区）队伍大数据平台</span>
              <dv-decoration-6 class="dv-dec-6"
                               :reverse="true"
                               :color="['#50e3c2', '#67a1e5']" />
            </div>
            <dv-decoration-8 class="dv-dec-8"
                             :reverse="true"
                             :color="['#568aea', '#000000']" />
          </div>
          <dv-decoration-10 class="dv-dec-10-s" />
        </div>

        <!-- 第二行 -->
        <div class="d-flex jc-between px-2">
          <div class="d-flex aside-width">
            <div class="react-left ml-2 react-l-s center cursor"
                 :class="item.id==active?'bg-color-blue':''"
                 v-for="(item,index) in streetList"
                 :key="index"
                 @click="changeStreet(item.id)">
              <span class="text">{{item.name}}</span>
            </div>
          </div>
          <div class="d-flex aside-width">
            <div class="react-right mr-2 react-l-s center cursor" :class="type==''?'bg-color-blue':''" @click="changeType('')">
              <!-- <span class="text fw-b">vue-big-screen</span> -->
              <span class="text">全部</span>
            </div>
            <div class="react-right mr-2 react-l-s center cursor" :class="type=='村'?'bg-color-blue':''" @click="changeType('村')">
              <!-- <span class="text fw-b">vue-big-screen</span> -->
              <span class="text">村</span>
            </div>
            <div class="react-right mr-2 react-l-s center cursor" :class="type=='社区'?'bg-color-blue':''" @click="changeType('社区')">
              <!-- <span class="text fw-b">vue-big-screen</span> -->
              <span class="text">社区</span>
            </div>
            <div class="react-right mr-4 react-l-s">
              <span class="react-after"></span>
              <span class="text">{{ dateYear }} {{ dateWeek }} {{ dateDay }}</span>
            </div>
          </div>
        </div>
        <div class="body-box">
          <!-- 第1列数据 -->
          <div class="content-box">
            <!-- 今日数据对比 -->
            <div>
              <dv-border-box-12>
                <leftTable :info="info.village_head" :active="active" :type="type"></leftTable>
              </dv-border-box-12>
            </div>
            <!-- 数据动态日志 -->
            <div>
              <dv-border-box-12>
                <centerRight1 :info="info.data_compare" />
              </dv-border-box-12>
            </div>
            <!-- 中间 -->
            <!-- <div>
              <center />
            </div> -->
            <!-- 中间 -->
            <!-- <div>
              <centerRight2 />
            </div> -->

          </div>

          <!-- 第2列数据 -->
          <div class="center-box">
            <!-- 地图 -->
            <dv-border-box-13>
              <smap :active="active" @changeStreet="changeStreet($event)"/>
            </dv-border-box-13>
            <div class="center-box-bottom">
              <div class="center-box-bottom-top">
                <!-- 岗位比例人数 -->
                <dv-border-box-12>
                  <bottomLeft :info="info.gangwei" />
                </dv-border-box-12>
                <!-- 待遇情况 -->
                <dv-border-box-12>
                  <!-- <centerLeft1 /> -->
                  <bottomLeft1 :info="info.daiyu" />
                </dv-border-box-12>
              </div>
              <div class="center-box-bottom-bottom">
                <!-- 一肩挑 -->
                <dv-border-box-12>
                  <!-- <centerLeft1 /> -->
                  <bottomLeft2 :info="info.jiantiao" />
                </dv-border-box-12>
                <!-- 特殊人群 -->
                <dv-border-box-12>
                  <!-- <centerLeft1 /> -->
                  <bottomLeft3 :info="info.special" />
                </dv-border-box-12>
              </div>
            </div>
          </div>
          <!-- 第3列数据 -->
          <div class="bototm-box">
            <!-- 党员 -->
            <dv-border-box-13>
              <centerLeft1 :info="info.dangyuan" />
            </dv-border-box-13>
            <!-- 年龄 -->
            <dv-border-box-12>
              <bottomRight :info="info.age" />
            </dv-border-box-12>
            <!-- 学历 -->
            <dv-border-box-12>
              <bottomRight1 :info="info.xueli" />
            </dv-border-box-12>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import drawMixin from "../utils/drawMixin";
import { formatTime } from '../utils/index.js'
import leftTable from './leftTable'
import centerLeft1 from './centerLeft1'
import smap from './map'
import centerRight1 from './centerRight1'
// import centerRight2 from './centerRight2'
// import center from './center'
import bottomLeft from './bottomLeft'
import bottomLeft1 from './bottomLeft1'
import bottomLeft2 from './bottomLeft2'
import bottomLeft3 from './bottomLeft3'
import bottomRight from './bottomRight'
import bottomRight1 from './bottomRight1'


export default {
  mixins: [drawMixin],
  data () {
    return {
      timing: null,
      loading: true,
      dateDay: null,
      dateYear: null,
      dateWeek: null,
      weekday: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
      info: {},
      streetList: [],
      active: '',
      type:''
    }
  },
  components: {
    leftTable,
    centerLeft1,
    smap,
    centerRight1,
    // centerRight2,
    // center,
    bottomLeft,
    bottomLeft1,
    bottomLeft2,
    bottomLeft3,
    bottomRight,
    bottomRight1
  },
  mounted () {
    this.timeFn()
    this.cancelLoading()
    this.getInfo()
    this.getStreetList()
    // setInterval(() => {
    //   this.getInfo()
    //   this.getStreetList()
    // }, 10000);
  },
  unMounted () {
    clearInterval(this.timing)
  },
  methods: {
    timeFn () {
      this.timing = setInterval(() => {
        this.dateDay = formatTime(new Date(), 'HH: mm: ss')
        this.dateYear = formatTime(new Date(), 'yyyy-MM-dd')
        this.dateWeek = this.weekday[new Date().getDay()]
      }, 1000)
    },
    cancelLoading () {
      setTimeout(() => {
        this.loading = false
      }, 500)
    },
    getInfo () {
      this.api
        .postAPI('/index/screen/getTodayDataCompare', {
          organize_id: this.active,
          type:this.type
        })
        .then((res) => {
          this.info = res.data.data
        })
    },
    getStreetList () {
      this.api
        .postAPI('/index/screen/getStreetList', {
        })
        .then((res) => {
          this.streetList = [{ id: '', name: '全部' }].concat(res.data.data)
          this.active = this.streetList[0].id
        })
    },
    changeStreet (id) {
      this.active = id
      this.getInfo()
    },
    changeType (type) {
      this.type = type
      this.getInfo()
    }
  }
}
</script>

<style lang="scss">
@import "../assets/scss/index.scss";
</style>
